home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 013 / size.arc / SIZE.XC < prev   
Encoding:
Text File  |  1987-01-10  |  7.9 KB  |  201 lines

  1.  
  2. SIZE.C                                                                Page 1
  3. [file d/t= 01/10/87  10:14]            [clock d/t= 10 January 1987  10:18:31]
  4.  
  5.  
  6.    1 #define LINT_ARGS 1
  7.    2 #include <dos.h>
  8.    3 #include <string.h>
  9.    4 #include <memory.h>
  10.    5 #include <stdio.h>
  11.    6 #include <process.h>
  12.    7 
  13.    8 main(argc, argv)
  14.    9 int argc;
  15.   10 char *argv[];
  16.   11 {
  17.   12 
  18.   13         int i, j;
  19.   14         char file_name[80];
  20.   15         static int num_files = 0;       /* number of files checked */
  21.   16         char dta[128];
  22.   17         static long total = 0;          /* total size of all files */
  23.   18         static long size = 0;
  24.   19         static long tot_cl[] = {0, 0, 0, 0};    /* total clusters required */
  25.   20         static long max_cl[] = {315, 354, 316, 355};
  26.   21         static char over[]="**OVER**";          /* overflow message */
  27.   22         static char noover[]="        ";        /* no overflow */
  28.   23         char far *fn_fp;
  29.   24         char far *dta_fp;
  30.   25         char *ovmsg[4];
  31.   26         union REGS inregs;
  32.   27         union REGS outregs;
  33.   28         struct SREGS segregs;
  34.   29 
  35.   30         fn_fp = file_name;
  36.   31         dta_fp = dta;
  37.   32 
  38.   33         if(argc > 1) {
  39.   34                 strcpy(file_name, argv[1]);
  40.   35                 if(!strchr(file_name, '.')) {
  41.   36                         if(file_name[strlen(file_name) - 1] != '\\')
  42.   37                                 strcat(file_name, "\\*.*");
  43.   38                         else
  44.   39                                 strcat(file_name, "*.*");
  45.   40                 }
  46.   41         } else
  47.   42                 strcpy(file_name, "*.*");
  48.   43 
  49.   44         segread(&segregs);              /* read current value of seg regs */
  50.   45 
  51.   46         inregs.h.ah = 0x1A;             /* set current dta address */
  52.   47         segregs.ds = FP_SEG(dta_fp);
  53.   48         inregs.x.dx = FP_OFF(dta_fp);
  54.   49         intdosx(&inregs, &outregs, &segregs);
  55.   50 
  56.   51         segregs.ds = FP_SEG(fn_fp);
  57.   52         inregs.x.dx = FP_OFF(fn_fp);
  58.   53         inregs.x.cx = 0;
  59.   54         inregs.h.ah = 0x4E;
  60.   55 
  61.  
  62. SIZE.C                                                                Page 2
  63. [file d/t= 01/10/87  10:14]            [clock d/t= 10 January 1987  10:18:31]
  64.  
  65.   56         intdosx(&inregs, &outregs, &segregs);   /* search for first file */
  66.   57 
  67.   58         if(outregs.x.cflag == 0) {              /* if file found */
  68.   59                 ++num_files;
  69.   60                 memcpy(&size, &dta[26], 4);
  70.   61                 for(i = 0, j = 1; i < 4; i++, j *= 2)
  71.   62                         tot_cl[i] += cluster(size, j);
  72.   63                 total += size;
  73.   64 
  74.   65                 do {                            /* find rest of files */
  75.   66                         inregs.h.ah = 0x4F;     /* find next file */
  76.   67                         intdos(&inregs, &outregs);
  77.   68 
  78.   69                         if(outregs.x.cflag == 0) {    /* if file found */
  79.   70                                 ++num_files;
  80.   71                                 memcpy(&size, &dta[26], 4);
  81.   72                                 for(i = 0, j = 1; i < 4; i++, j *= 2)
  82.   73                                         tot_cl[i] += cluster(size, j);
  83.   74                                 total += size;
  84.   75                         }
  85.   76                 } while (outregs.x.cflag == 0);
  86.   77         }
  87.   78 
  88.   79         printf("\n\nNOTE:  FULL PATHNAMES AND/OR FILENAMES MAY BE USED");
  89.   80         printf(" AS ARGUMENT ON PROGRAM LINE");
  90.   81         printf("\n\n\tNumber of files = %d     Total size = %ld bytes",
  91.   82                 num_files, total);
  92.   83 
  93.   84         printf("\n\n\n       ");
  94.   85         printf("TOTAL STORAGE REQUIRED IN BYTES FOR THE FOLLOWING DISKS");
  95.   86         printf("\n\n   160K SS     180K SS     320K DS     360K DS     ");
  96.   87         printf("10 MEG     20+MEG");
  97.   88         printf("\n   floppy      floppy      floppy      floppy       ");
  98.   89         printf("hard       hard");
  99.   90         printf("\n\n  %8ld    %8ld    %8ld    %8ld   %8ld   %8ld",
  100.   91                 tot_cl[0] * 512L, tot_cl[0] * 512L, tot_cl[1] * 1024L,
  101.   92                 tot_cl[1] * 1024L, tot_cl[3] * 4096L, tot_cl[2] * 2048L);
  102.   93         for(i = 0; i < 2; i++)
  103.   94                 if(tot_cl[0] > max_cl[i])
  104.   95                         ovmsg[i] = over;
  105.   96                 else
  106.   97                         ovmsg[i] = noover;
  107.   98         for(; i < 4; i++)
  108.   99                 if(tot_cl[1] > max_cl[i])
  109.  100                         ovmsg[i] = over;
  110.  101                 else
  111.  102                         ovmsg[i] = noover;
  112.  103         printf("\n  %s    %s    %s    %s\n\n", ovmsg[0], ovmsg[1], ovmsg[2],
  113.  104                 ovmsg[3]);
  114.  105 
  115.  106         exit(0);
  116.  107 
  117.  108 }
  118.  109 
  119.  110 cluster(file_size, num_sec)
  120.  111 long file_size;
  121.  
  122. SIZE.C                                                                Page 3
  123. [file d/t= 01/10/87  10:14]            [clock d/t= 10 January 1987  10:18:31]
  124.  
  125.  112 int num_sec;
  126.  113 {
  127.  114 
  128.  115         int num_clust;          /* number of clusters required */
  129.  116 
  130.  117         num_sec *= 512;         /* number of bytes per cluster */
  131.  118         num_clust = file_size / (long)num_sec;
  132.  119         if(file_size > ((long)num_sec * (long)num_clust))
  133.  120                 ++num_clust;
  134.  121 
  135.  122         return(num_clust);
  136.  123 
  137.  124 }
  138.  125 
  139. SIZE.C                                                                Page 4
  140. [file d/t= 01/10/87  10:14]            [clock d/t= 10 January 1987  10:18:31]
  141.  
  142.  
  143. ah            : 46    54    66    
  144. argc          : 8     9     33    
  145. argv          : 8     10    34    
  146. cflag         : 58    69    76    
  147. cluster       : 62    73    110   
  148. cx            : 53    
  149. ds            : 47    51    
  150. dta           : 16    31    60    71    
  151. dta_fp        : 24    31    47    48    
  152. dx            : 48    52    
  153. exit          : 106   
  154. FP_OFF        : 48    52    
  155. FP_SEG        : 47    51    
  156. far           : 23    24    
  157. file_name     : 14    30    34    35    36    36    37    39    
  158.               : 42    
  159. file_size     : 110   111   118   119   
  160. fn_fp         : 23    30    51    52    
  161. h             : 46    54    66    
  162. i             : 13    61    61    61    62    72    72    72    
  163.               : 73    93    93    93    94    95    97    98    
  164.               : 98    99    100   102   
  165. inregs        : 26    46    48    49    52    53    54    56    
  166.               : 66    67    
  167. intdos        : 67    
  168. intdosx       : 49    56    
  169. j             : 13    61    61    62    72    72    73    
  170. L             : 91    91    
  171. LINT_ARGS     : 1     
  172. main          : 8     
  173. max_cl        : 20    94    99    
  174. memcpy        : 60    71    
  175. noover        : 22    97    102   
  176. num_clust     : 115   118   119   120   122   
  177. num_files     : 15    59    70    82    
  178. num_sec       : 110   112   117   118   119   
  179. outregs       : 27    49    56    58    67    69    76    
  180. over          : 21    95    100   
  181. ovmsg         : 25    95    97    100   102   103   103   103   
  182.               : 104   
  183. printf        : 79    80    81    84    85    86    87    88    
  184.               : 89    90    103   
  185. REGS          : 26    27    
  186. SREGS         : 28    
  187. segread       : 44    
  188. segregs       : 28    44    47    49    51    56    
  189. size          : 18    60    62    63    71    73    74    
  190. strcat        : 37    39    
  191. strchr        : 35    
  192. strcpy        : 34    42    
  193. strlen        : 36    
  194. tot_cl        : 19    62    73    91    91    91    92    92    
  195.               : 92    94    99    
  196. total         : 17    63    74    82    
  197. x             : 48    52    53    58    69    76    
  198.  
  199. SIZE.C                                                                Page 5
  200. [file d/t= 01/10/87  10:14]            [clock d/t= 10 January 1987  10:18:31]
  201.  
  202.  
  203.  
  204. Allowable Symbols: 749
  205. Unique    Symbols: 48
  206.